package view;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JComponent;

import utilities.Constants;

class ImagePanel extends JComponent {
    /**
	 * 
	 */
	private static final long serialVersionUID = -7542479733689292955L;
	private Image image;
    public ImagePanel(String path) {
    	Image backImage = this.setImage(path);
        this.image = backImage;
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        g.drawImage(image, 0, 0, null);
    }
    
    private Image setImage(String path){
    	BufferedImage img = null;
		try {
		    img = ImageIO.read(new File(path));
		} catch (IOException e) {
		    e.printStackTrace();
		}
		Image scaledInstance = img.getScaledInstance(Constants.PANEL_WIDTH, Constants.PANEL_HEIGHT,
				Image.SCALE_SMOOTH);
		return scaledInstance;
    }
    
    public static Image getImage(String path){
    	Image img = null;
    	try {
    	    img = ImageIO.read(new File(path));
    	  } catch (IOException ex) {
    	  }
    	return img;
    }
}